
package com.ostrich.project.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.base.util.HtmlUtil;
import com.base.web.BaseAction;
import com.ostrich.common.OstrichConstants;
import com.ostrich.manpower.bean.TostHrBaseinfo;
import com.ostrich.manpower.bean.TostHrPostinfo;
import com.ostrich.manpower.service.impl.TostHrBaseinfoService;
import com.ostrich.manpower.service.impl.TostHrDepartinfoService;
import com.ostrich.manpower.service.impl.TostHrPostinfoService;
import com.ostrich.project.bean.TostPjBudgetinfo;
import com.ostrich.project.bean.TostPjProjcttab;
import com.ostrich.project.bean.TostPjTeammemberinfo;
import com.ostrich.project.service.impl.TostPjBudgetinfoService;
import com.ostrich.project.service.impl.TostPjProjcttabService;
import com.ostrich.project.service.impl.TostPjTeammemberinfoService;
import com.ostrich.system.analysis.ParaminfoUtil;
import com.ostrich.system.bean.TostSysParaminfo;
import com.ostrich.system.service.impl.TostSysParaminfoService;

/**
 * ClassName: Controller <br/>
 * date: 2013-5-9 下午03:07:38 <br/>
 * 
 * @author wangyinan
 * @version
 */                
@Controller         
@RequestMapping("/tostPjLookDetailsinfo")
public class TostPjLookDetailsController extends BaseAction
{
	private final static Logger log= Logger.getLogger(TostPjBudgetinfoController.class);

	// Servrice start
	@Autowired(required=false) //自动注入，不需要生成set方法了，required=false表示没有实现类，也不会报错。
	private TostPjBudgetinfoService<TostPjBudgetinfo> tostPjBudgetinfoService; 
	
	
	@Autowired(required=false) //自动注入，不需要生成set方法了，required=false表示没有实现类，也不会报错。
	private TostPjTeammemberinfoService<TostPjTeammemberinfo> tostpjteammemberinfoService;
	
	@Autowired(required=false)
	private TostSysParaminfoService<TostSysParaminfo> tostsysparaminfoservice;
	
	@Autowired(required=false)
	private TostHrBaseinfoService<TostHrBaseinfo> tosthrbaseinfoservice;
	
	@Autowired(required=false) //自动注入，不需要生成set方法了，required=false表示没有实现类，也不会报错。
	private TostHrPostinfoService<TostHrPostinfo> tostHrPostinfoService; 
	
	@Autowired(required=false)
	private TostHrDepartinfoService<TostHrBaseinfo> tosthrDepartinfoService;
	
	@Autowired(required=false)
	private TostPjProjcttabService<TostPjProjcttab> tostpjprojcttabservice;

	public String hdp_id;
	public Integer pjid;
	/**
	 * ilook 首页
	 * @param url
	 * @param classifyId
	 * @return
	 */
	@RequestMapping("/list") 
	public ModelAndView  list(TostPjTeammemberinfo tostPjTeammemberinfo,HttpServletRequest request) throws Exception{
		 hdp_id=tostPjTeammemberinfo.getHdpId();
		Map<String,Object>  context = getRootMap();
		context.put("nowstate", ParaminfoUtil.getParamByPid(OstrichConstants.PARMPJ_PRIJECT_STATE));//获取当前状态
		
		List<Map<String, Object>> dataList = tostpjteammemberinfoService.queryprijectByhdpid(hdp_id);
		context.put("hdpName", (dataList!=null&&dataList.size()>0)?dataList.get(0).get("hdpName"):"");

		//context.put("pjId", tostPjTeammemberinfo.getPjId());
		context.put("hdpId", hdp_id);
		//设置页面数据
		return forword("project/tabTostPjLookDetails",context); 
	}
	//多个tostPjTeammemberinfo参数 
	@RequestMapping("/cost") 
	public ModelAndView  cost(TostPjTeammemberinfo tostPjTeammemberinfo,HttpServletRequest request) throws Exception{
		Map<String,Object>  context = getRootMap();
		context.put("nowstate", ParaminfoUtil.getParamByPid(OstrichConstants.PARMPJ_PRIJECT_STATE));//获取当前状态
		
		List<Map<String, Object>> dataList = tostpjteammemberinfoService.queryproject(tostPjTeammemberinfo);
		context.put("hdpName", (dataList!=null&&dataList.size()>0)?dataList.get(0).get("hdpName"):"");
		//设置页面数据
		return forword("project/tabTostPjLookCost",context); 
	}
	@RequestMapping("/datacost") 
	public void  datacost(TostPjTeammemberinfo tostPjTeammemberinfo,HttpServletResponse response) throws Exception{
		Integer rowCount =tostpjteammemberinfoService.queryCountpro(tostPjTeammemberinfo);
		tostPjTeammemberinfo.getPager().setRowCount(rowCount);
		List<Map<String, Object>> dataList = tostpjteammemberinfoService.queryproject(tostPjTeammemberinfo);
		//设置页面数据
		Map<String,Object> jsonMap = new HashMap<String,Object>();
		jsonMap.put("total",rowCount);
	    jsonMap.put("rows", dataList);
	    HtmlUtil.writerJson(response, jsonMap);
	}
	
	/**
	 * json 列表页面
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/dataList") 
	public void  dataList(TostPjTeammemberinfo tostPjTeammemberinfo,HttpServletResponse response) throws Exception{
		List<Map<String, Object>> dataList = tostpjteammemberinfoService.queryprijectByhdpid(hdp_id);
		//设置页面数据
		Map<String,Object> jsonMap = new HashMap<String,Object>();
		jsonMap.put("total",tostPjTeammemberinfo.getPager().getRowCount());
	    jsonMap.put("rows", dataList);
	    HtmlUtil.writerJson(response, jsonMap);
	}
//查询参加改项目的人；
	@RequestMapping("/queryperBydpid") 
	public void  dataList1(TostPjTeammemberinfo tostPjTeammemberinfo,HttpServletResponse response) throws Exception{
		pjid=tostPjTeammemberinfo.getPjId();
		String dd=tostPjTeammemberinfo.getHdpId();
		List<TostPjTeammemberinfo> dataList=tostpjteammemberinfoService.queryperBydpid(tostPjTeammemberinfo.getHdpId(),pjid);
		//设置页面数据
		
		Map<String,Object> jsonMap = new HashMap<String,Object>();
		jsonMap.put("total",(dataList!=null)?dataList.size():0);
	    jsonMap.put("rows", dataList);
	    HtmlUtil.writerJson(response, jsonMap);
	}
	//查询当前状态      
@RequestMapping("/querynowstat")
public void queryBypostname(HttpServletResponse response ){
	Map<Integer, TostSysParaminfo> cmps = ParaminfoUtil.getParamByPid(OstrichConstants.PARMPJ_PRIJECT_STATE);
	List<TostSysParaminfo> ls = new ArrayList<TostSysParaminfo>();
	for(Map.Entry<Integer, TostSysParaminfo> cp:cmps.entrySet()){
		ls.add(cp.getValue());
	}
	HtmlUtil.writerJson(response, ls);
}
//插入到人员团队信息
@RequestMapping("/insertTeamMesseag")
public ModelAndView insertTeamMesseag(TostPjTeammemberinfo tbf,HttpServletRequest request) throws Exception{
	Map<String,Object>  context = getRootMap();
	Integer hrId=tbf.getHrId();
	//查出tosthrbaseinfo对象
	TostHrBaseinfo tb = (TostHrBaseinfo) tosthrbaseinfoservice.queryById(hrId);
	//人员姓名
	tbf.setHrName(tb.getHrName());
	//基础id
	tbf.setHrId(hrId);
	//项目编号
	tbf.setPjId(pjid);
	//所属部门
	tbf.setHdpId(hdp_id);
	//部门名称
    System.out.println(tosthrDepartinfoService.querydnameByid(hdp_id));
	tbf.setHdpName(tosthrDepartinfoService.querydnameByid(hdp_id));
	//岗位名称
	tbf.setHpoName(tbf.getHpoName());
	
	System.out.println(tostHrPostinfoService.queryidByname(tbf.getHpoName()));
	tbf.setHpoId(tostHrPostinfoService.queryidByname(tbf.getHpoName()));
	tostpjteammemberinfoService.add(tbf);
	
	return forword("project/tabTostPjLookDetails",context); 
}

	@RequestMapping("/depart") 
	public ModelAndView  depart(TostPjProjcttab tostpjprojcttab,HttpServletRequest request) throws Exception{
		Map<String,Object>  context = getRootMap();
		tostpjprojcttab =tostpjprojcttabservice.queryById(tostpjprojcttab.getId());
		context.put("pjId",tostpjprojcttab.getId());
		context.put("pjName",tostpjprojcttab.getPjProjectname());
		//设置页面数据
		return forword("project/tabTostPjDepartment",context); 
	}
	
}






